/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import java.awt.Component;
import java.awt.Image;
import java.net.URI;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import utilities.ExtensionFileFilter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import popups.PopupParser;

/**
 *
 * @author icdev
 */
class ResourceFile extends File {

    public ResourceFile(String fileName) {
        super(fileName);
    }

    public ResourceFile(File parent, String fileName) {
        super(parent, fileName);
    }

    public ResourceFile(URI uri) {
        super(uri);
    }

    public ResourceFile(String parent, String fileName) {
        super(parent, fileName);
    }

    public String toString() {
        return this.getName();
    }
}

class ResourceFileChooser extends JFileChooser {

    public ResourceFileChooser() {
        super();
    }

    public Vector<ResourceFile> getResourceFiles() {
        Vector<ResourceFile> resFiles = new Vector<ResourceFile>();
        for (File fil : this.getSelectedFiles()) {
            ResourceFile rsFile = new ResourceFile(fil.getPath());
            resFiles.add(rsFile);
        }
        return resFiles;
    }
}

public class JResourcesManager extends javax.swing.JInternalFrame {

    Vector<ResourceFile> BandFiles = new Vector<ResourceFile>();
    Vector<ResourceFile> MarkerFiles = new Vector<ResourceFile>();
    Vector<ResourceFile> SmearFiles = new Vector<ResourceFile>();
    Vector<ResourceFile> DimerFiles = new Vector<ResourceFile>();
    Vector<ResourceFile> ProtienFiles = new Vector<ResourceFile>();
    Vector<ResourceFile> HouseKeepingFiles = new Vector<ResourceFile>();
    DefaultTableModel smearsModel;
    DefaultTableModel dimersModel;
    DefaultTableModel bandsModel;
    DefaultTableModel housekeepingsModel;

    /**
     * Creates new form JResourcesManager
     */
    class ImageRenderer extends DefaultTableCellRenderer {

        JLabel lbl = new JLabel();

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Image img = ((ImageIcon) value).getImage();
            ImageIcon icon = new ImageIcon(img.getScaledInstance(100, 25, Image.SCALE_AREA_AVERAGING));
            lbl.setIcon(icon);
            return lbl;
        }
    }

    public JResourcesManager() {
        initComponents();
        DefaultListModel lstModel = new DefaultListModel();
        allResourcesList.setModel(lstModel);
        DefaultListModel lstModel2 = new DefaultListModel();
        specialResoursesList.setModel(lstModel2);
        jButton11.setText("Add Bands");

        bandsModel = PopupParser.getComponents("Band");
        smearsModel = PopupParser.getComponents("Smear");
        dimersModel = PopupParser.getComponents("Dimer");
        housekeepingsModel = PopupParser.getComponents("HouseKeeping");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        allResourcesList = new javax.swing.JList();
        specialResoursesPane = new javax.swing.JScrollPane();
        specialResoursesList = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton12 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Add new Resources"));
        jPanel1.setLayout(null);

        allResourcesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                allResourcesListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(allResourcesList);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(18, 31, 210, 191);

        specialResoursesList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                specialResoursesListValueChanged(evt);
            }
        });
        specialResoursesPane.setViewportView(specialResoursesList);

        jPanel1.add(specialResoursesPane);
        specialResoursesPane.setBounds(308, 62, 210, 160);

        jButton1.setText("<");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(240, 150, 60, 29);

        jButton3.setText("|<");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3);
        jButton3.setBounds(240, 180, 60, 29);

        jButton2.setText("Clear");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(160, 230, 70, 29);

        jButton4.setText(">|");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton4);
        jButton4.setBounds(240, 120, 60, 29);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bands", "Markers", "HouseKeepings", "Protiens", "Smears", "Dimers" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jPanel1.add(jComboBox1);
        jComboBox1.setBounds(310, 30, 210, 27);

        jButton7.setText(">");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton7);
        jButton7.setBounds(240, 90, 60, 29);

        jButton8.setText("Add Resourse");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton8);
        jButton8.setBounds(20, 230, 140, 29);

        jButton5.setText("Clear");
        jPanel1.add(jButton5);
        jButton5.setBounds(160, 230, 70, 29);

        jButton9.setText("Add Resourse");
        jPanel1.add(jButton9);
        jButton9.setBounds(20, 230, 120, 29);

        jButton10.setText("Clear");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton10);
        jButton10.setBounds(450, 230, 70, 29);

        jButton11.setText("Apply");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton11);
        jButton11.setBounds(310, 230, 140, 29);
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 270, 210, 70);
        jPanel1.add(jLabel2);
        jLabel2.setBounds(310, 270, 210, 70);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 10, 540, 360);

        jPanel2.setLayout(null);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Selected", "Resource", "Resource Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jPanel2.add(jScrollPane2);
        jScrollPane2.setBounds(0, 0, 540, 140);

        jButton12.setText("Apply");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton12);
        jButton12.setBounds(310, 230, 140, 29);

        jButton6.setText("Remove");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton6);
        jButton6.setBounds(0, 150, 130, 29);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(10, 380, 540, 200);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        DefaultListModel lstModel2 = (DefaultListModel) allResourcesList.getModel();
        DefaultListModel lstModel = (DefaultListModel) specialResoursesList.getModel();
        for (int i = 0; i < lstModel.size(); i++) {
            ResourceFile rsFile = (ResourceFile) lstModel.getElementAt(i);
            lstModel2.addElement(rsFile);
            switch (this.jComboBox1.getSelectedIndex()) {
                case 0:
                    BandFiles.clear();
                    break;
                case 1:
                    MarkerFiles.clear();
                    break;
                case 2:
                    HouseKeepingFiles.clear();
                    break;
                case 3:
                    ProtienFiles.clear();
                    break;
                case 4:
                    SmearFiles.clear();
                    break;
                case 5:
                    DimerFiles.clear();
                    break;
            }
        }

        lstModel.clear();
        specialResoursesList.setModel(lstModel);
        allResourcesList.setModel(lstModel2);
    }//GEN-LAST:event_jButton3ActionPerformed
    void copyFile(File src, File dst) {
        try {
            InputStream in = new FileInputStream(src);
            OutputStream out = new FileOutputStream(dst);

            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (IOException ex) {
        }
    }
    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        try {

            Vector<ResourceFile> SourceItems = new Vector<ResourceFile>();
            String distNode = "";
            String subDistNode = "";
            switch (this.jComboBox1.getSelectedIndex()) {
                case 0:
                    SourceItems = BandFiles;
                    distNode = "Bands";
                    subDistNode = "Band";
                    break;
                case 1:
                    SourceItems = MarkerFiles;
                    distNode = "Markers";
                    subDistNode = "Marker";
                    break;
                case 2:
                    SourceItems = HouseKeepingFiles;
                    distNode = "HouseKeepings";
                    subDistNode = "HouseKeeping";
                    break;
                case 3:
                    SourceItems = ProtienFiles;
                    distNode = "Proteins";
                    subDistNode = "Protein";
                    break;
                case 4:
                    SourceItems = SmearFiles;
                    distNode = "Smears";
                    subDistNode = "Smear";
                    break;
                case 5:
                    SourceItems = DimerFiles;
                    distNode = "Dimers";
                    subDistNode = "Dimer";
                    break;
            }
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(false);
            DocumentBuilder docbuilder = factory.newDocumentBuilder();

            Document doc = docbuilder.parse(new File("resources/Resources.xml"));
            Element documentElement = doc.getDocumentElement();

            NodeList nodlst = doc.getElementsByTagName(distNode);
            for (ResourceFile rsfile : SourceItems) {
                Element nodeElement = doc.createElement(subDistNode);
                nodeElement.setAttribute("type", subDistNode);
                nodeElement.setAttribute("image_url", rsfile.getName());
                nodlst.item(0).appendChild(nodeElement);
                File newf = new File("resources/" + distNode.toLowerCase() + "/" + rsfile.getName());
                copyFile(rsfile, newf);
            }


            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            FileOutputStream sw = new FileOutputStream("resources/Resources.xml");
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            trans.transform(source, result);

            DefaultListModel lstModel = (DefaultListModel) specialResoursesList.getModel();
            lstModel.clear();
            allResourcesList.setModel(lstModel);
            switch (this.jComboBox1.getSelectedIndex()) {
                case 0:
                    BandFiles.clear();
                    break;
                case 1:
                    MarkerFiles.clear();
                    break;
                case 2:
                    HouseKeepingFiles.clear();
                    break;
                case 3:
                    ProtienFiles.clear();
                    break;
                case 4:
                    SmearFiles.clear();
                    break;
                case 5:
                    DimerFiles.clear();
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        ResourceFileChooser jfc = new ResourceFileChooser();
        ExtensionFileFilter filesFilterPNG = new ExtensionFileFilter("Image Files(png)", new String[]{"png"});
        jfc.addChoosableFileFilter(filesFilterPNG);
        jfc.setFileFilter(filesFilterPNG);
        jfc.setMultiSelectionEnabled(true);
        if (jfc.showOpenDialog(this) == ResourceFileChooser.APPROVE_OPTION) {
            Vector<ResourceFile> selFiles = jfc.getResourceFiles();
            DefaultListModel lstModel = (DefaultListModel) allResourcesList.getModel();
            for (ResourceFile fil : selFiles) {
                lstModel.addElement(fil);
            }
            allResourcesList.setModel(lstModel);

        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void allResourcesListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_allResourcesListValueChanged
        ResourceFile rsFile = (ResourceFile) allResourcesList.getSelectedValue();
        if (rsFile != null) {
            Icon icn = new javax.swing.ImageIcon(rsFile.getPath());
            Image img = ((ImageIcon) icn).getImage();
            ImageIcon icon = new ImageIcon(img.getScaledInstance(this.jLabel1.getSize().width, this.jLabel1.getSize().height, Image.SCALE_AREA_AVERAGING));
            this.jLabel1.setIcon(icon);
        }

    }//GEN-LAST:event_allResourcesListValueChanged

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        ResourceFile rsFile = (ResourceFile) allResourcesList.getSelectedValue();
        DefaultListModel lstModel = (DefaultListModel) specialResoursesList.getModel();
        lstModel.addElement(rsFile);
        specialResoursesList.setModel(lstModel);
        switch (this.jComboBox1.getSelectedIndex()) {
            case 0:
                BandFiles.add(rsFile);
                break;
            case 1:
                MarkerFiles.add(rsFile);
                ;
                break;
            case 2:
                HouseKeepingFiles.add(rsFile);
                ;
                break;
            case 3:
                ProtienFiles.add(rsFile);
                ;
                break;
            case 4:
                SmearFiles.add(rsFile);
                ;
                break;
            case 5:
                DimerFiles.add(rsFile);
                ;
                break;
        }
        DefaultListModel lstModel2 = (DefaultListModel) allResourcesList.getModel();
        lstModel2.removeElement(rsFile);
        allResourcesList.setModel(lstModel2);

    }//GEN-LAST:event_jButton7ActionPerformed

    private void specialResoursesListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_specialResoursesListValueChanged
        ResourceFile rsFile = (ResourceFile) specialResoursesList.getSelectedValue();
        if (rsFile != null) {
            Icon icn = new javax.swing.ImageIcon(rsFile.getPath());
            Image img = ((ImageIcon) icn).getImage();
            ImageIcon icon = new ImageIcon(img.getScaledInstance(this.jLabel2.getSize().width, this.jLabel2.getSize().height, Image.SCALE_AREA_AVERAGING));
            this.jLabel2.setIcon(icon);
        }
    }//GEN-LAST:event_specialResoursesListValueChanged

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DefaultListModel lstModel2 = (DefaultListModel) allResourcesList.getModel();
        DefaultListModel lstModel = (DefaultListModel) specialResoursesList.getModel();
        for (int i = 0; i < lstModel2.size(); i++) {
            ResourceFile rsFile = (ResourceFile) lstModel2.getElementAt(i);
            lstModel.addElement(rsFile);
            switch (this.jComboBox1.getSelectedIndex()) {
                case 0:
                    BandFiles.add(rsFile);
                    break;
                case 1:
                    MarkerFiles.add(rsFile);
                    ;
                    break;
                case 2:
                    HouseKeepingFiles.add(rsFile);
                    ;
                    break;
                case 3:
                    ProtienFiles.add(rsFile);
                    ;
                    break;
                case 4:
                    SmearFiles.add(rsFile);
                    ;
                    break;
                case 5:
                    DimerFiles.add(rsFile);
                    ;
                    break;
            }
        }
        specialResoursesList.setModel(lstModel);

        lstModel2.clear();
        allResourcesList.setModel(lstModel2);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged

        Vector<ResourceFile> SourceItems = new Vector<ResourceFile>();
        DefaultTableModel SourceTable = new DefaultTableModel();
        String distNode = "";
        switch (this.jComboBox1.getSelectedIndex()) {
            case 0:
                SourceItems = BandFiles;
                SourceTable = bandsModel;
                distNode = "bands";
                break;
            case 1:
                SourceItems = MarkerFiles;
                distNode = "markers";
                break;
            case 2:
                SourceItems = HouseKeepingFiles;
                SourceTable = housekeepingsModel;
                distNode = "housekeepings";
                break;
            case 3:
                SourceItems = ProtienFiles;
                distNode = "proteins";
                break;
            case 4:
                SourceItems = SmearFiles;
                SourceTable = smearsModel;
                distNode = "smears";
                break;
            case 5:
                SourceItems = DimerFiles;
                SourceTable = dimersModel;
                distNode = "dimers";
                break;
        }
        jButton11.setText("Add " + jComboBox1.getSelectedItem().toString());
        DefaultListModel newLst = new DefaultListModel();
        for (ResourceFile fil : SourceItems) {
            newLst.addElement(fil);
        }
        this.specialResoursesList.setModel(newLst);
        DefaultTableModel Tmodel = (DefaultTableModel) jTable1.getModel();
        jTable1.getColumnModel().getColumn(1).setCellRenderer(new ImageRenderer());
        Tmodel.setRowCount(0);
        for (int i = 0; i < SourceTable.getRowCount(); i++) {
            ImageIcon icon2 = new ImageIcon("resources/" + distNode.toLowerCase() + "/" + SourceTable.getValueAt(i, 1));
            Tmodel.addRow(new Object[]{false, icon2, SourceTable.getValueAt(i, 1)});
        }
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();


    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ResourceFile rsFile = (ResourceFile) specialResoursesList.getSelectedValue();
        DefaultListModel lstModel = (DefaultListModel) allResourcesList.getModel();
        lstModel.addElement(rsFile);
        allResourcesList.setModel(lstModel);
        switch (this.jComboBox1.getSelectedIndex()) {
            case 0:
                BandFiles.remove(rsFile);
                break;
            case 1:
                MarkerFiles.remove(rsFile);
                ;
                break;
            case 2:
                HouseKeepingFiles.remove(rsFile);
                ;
                break;
            case 3:
                ProtienFiles.remove(rsFile);
                ;
                break;
            case 4:
                SmearFiles.remove(rsFile);
                ;
                break;
            case 5:
                DimerFiles.remove(rsFile);
                ;
                break;
        }
        DefaultListModel lstModel2 = (DefaultListModel) specialResoursesList.getModel();
        lstModel2.removeElement(rsFile);
        specialResoursesList.setModel(lstModel2);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        DefaultListModel lstModel2 = (DefaultListModel) allResourcesList.getModel();
        lstModel2.clear();
        allResourcesList.setModel(lstModel2);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        switch (this.jComboBox1.getSelectedIndex()) {
            case 0:
                BandFiles.clear();
                break;
            case 1:
                MarkerFiles.clear();

                break;
            case 2:
                HouseKeepingFiles.clear();

                break;
            case 3:
                ProtienFiles.clear();

                break;
            case 4:
                SmearFiles.clear();

                break;
            case 5:
                DimerFiles.clear();

                break;
        }
        DefaultListModel lstModel2 = (DefaultListModel) specialResoursesList.getModel();
        lstModel2.clear();
        specialResoursesList.setModel(lstModel2);
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        try {

            String distNode = "";
            String subDistNode = "";
            switch (this.jComboBox1.getSelectedIndex()) {
                case 0:
                    distNode = "Bands";
                    subDistNode = "Band";
                    break;
                case 1:
                    distNode = "Markers";
                    subDistNode = "Marker";
                    break;
                case 2:
                    distNode = "HouseKeepings";
                    subDistNode = "HouseKeeping";
                    break;
                case 3:
                    distNode = "Proteins";
                    subDistNode = "Protein";
                    break;
                case 4:
                    distNode = "Smears";
                    subDistNode = "Smear";
                    break;
                case 5:
                    distNode = "Dimers";
                    subDistNode = "Dimer";
                    break;
            }
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(false);
            DocumentBuilder docbuilder = factory.newDocumentBuilder();

            Document doc = docbuilder.parse(new File("resources/Resources.xml"));
            Element documentElement = doc.getDocumentElement();

            NodeList nScene = doc.getElementsByTagName(distNode);
            NodeList nScene1 = nScene.item(0).getChildNodes();

            Vector<String> nodes2Remove = new Vector<String>();
            DefaultTableModel defModel = (DefaultTableModel) jTable1.getModel();
            for (int a = 0; a < defModel.getRowCount(); a++) {
                boolean isSelected = (boolean) defModel.getValueAt(a, 0);
                if (isSelected) {
                    nodes2Remove.add(defModel.getValueAt(a, 2).toString());
                    defModel.removeRow(a);
                }
            }
            for (int i = 0; i < nScene1.getLength(); i++) {
                Node n = nScene1.item(i);
                if (n.getNodeType() != 3) {
                    Element elm = (Element) n;
                    String imageValue = elm.getAttribute("image_url");
                    if (nodes2Remove.contains(elm.getAttribute("image_url"))) {

                        nScene.item(0).removeChild(n);
                        File file2delete = new File("resources/" + distNode.toLowerCase() + "/" + imageValue);
                        file2delete.delete();
                    }
                } else {
                    continue;
                }

            }
            jTable1.setModel(defModel);
            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();
            trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            FileOutputStream sw = new FileOutputStream("resources/Resources.xml");
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            trans.transform(source, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton6ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList allResourcesList;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JList specialResoursesList;
    private javax.swing.JScrollPane specialResoursesPane;
    // End of variables declaration//GEN-END:variables
}
